// JavaScript Document
// JavaScript Document
function expt_click()
{
	
	$("#table1").table2excel({

  // 不被导出的表格行的CSS class类

  exclude: ".noExl",

  // 导出的Excel文档的名称

  name: "ex",

  // Excel文件的名称

  filename: "推广大师导出"

});
	
}

function btn_click()
{
	 var startDay=$("#txtBeginDate").val();
	 var endDay=$("#txtEndDate").val();
	var today_start=$("#txtBeginDate").val()+" 00:00:01";
	var today_end=$("#txtEndDate").val()+" 23:59:59";
	var where_s="";
	if(startDay.length>3)
		 where_s=" and `timex`>'"+today_start+"'";
	 if(endDay.length>3)
	 	 where_s=where_s+" and `timex`<'"+today_end+"'";
	var prtid=$("#prtid").val();
	if(prtid.length>0)
	 	 where_s+=" and parent_id='"+prtid+"'";
	var sql="select * from agt_v  where 1=1 $exp$ order by id desc limit 100 ";
	
	//if(urole=="admin")
	//	sql=" select sum(rmb) sumx from acc_rechg  where status=1 and  (promoter is null or promoter='')   ";
		
	sql=sql.replace("$exp$",where_s);
	console.log("my mem totle:"+sql);
	 
		   	
		   
		 var code="com.attilax.ioc.Ioc4agent.getBean(com.attilax.agent.AgentRechargeService.class).RchgSum_grpby_hiagt()";
	 console.log("--dsl:"+code);
//	 var sql="select sum(rmb) sumx, hiagt_id,hiagt_nick from rchg_agt_hiagt GROUP BY hiagt_id";
 //code=code.replace("$pid$",pid);
 	var jsbrj=new	AtiJsBridgV13();
	jsbrj.backend_url="/DslAjaxJsbridgeServletV2";
	//	jsbrj.method="post";
		//var para={};
		var prar=$("form").serialize();
		if(startDay.length>3)
		prar+="&startDate="+today_start;
		 if(endDay.length>3)
		prar+="&endDay="+today_end;
	 	prar+="&dsl="+encodeURIComponent(code);
		 prar+="&retFmt=json";
	//	para.retFmt="";
		jsbrj.exe(prar,function(data){
			console.log(data);
			//$("#content").val(data);
			
			
			 var json=JSON.parse(data); //( data );			 	 
		  	var obj=json[0];
	 	   var list=new TableV3("table1");
		 
			list.bindData(json);
			
		});
	 
	
}


 function today_add()
{
		var today_str=today_local();
		var today_start=today_str+" 00:00:01";
	var today_end=today_str+" 23:59:59";

	 var sql="select count(*)  cnt   from hiagt where   timex>'$sdd$' and timex<'$end$'   "; 
   sql=sql.replace("$sdd$",today_start);
   sql=sql.replace("$end$",today_end);
   
   
			var orm=new atiOrmV5();
		orm.iniQbj();
		orm.obj=sql ;
	    orm.metaParam="retFmt=json";
		 
	orm.callbackFun=function(data)
	{
		
			try{
			  processJavaEx_V2q315(data);
		   }catch(e)
		   {
			 
				 
				  showErr(e);
				  return;
		  
		   }
		   var json=str2json(data);
		 	var obj=json[0];
			$("#cnt").text(obj.cnt);
		  
		   
	};
	orm.query();
	
}

function  page_load()
{
	 console.log("--page_load:");
	var pid=UrlParm.parm('parent_id');
	 var code="com.attilax.ioc.Ioc4agent.getBean(com.attilax.agent.AgentRechargeService.class).RchgSum_grpby_hiagt()";
	 console.log("--dsl:"+code);
//	 var sql="select sum(rmb) sumx, hiagt_id,hiagt_nick from rchg_agt_hiagt GROUP BY hiagt_id";
 code=code.replace("$pid$",pid);
 	var jsbrj=new	AtiJsBridgV13();
	jsbrj.backend_url="/DslAjaxJsbridgeServletV2";
	//	jsbrj.method="post";
		var para={};
		para.dsl=code;
		para.retFmt="json";
		jsbrj.exe(para,function(data){
			console.log(data);
			//$("#content").val(data);
			
			
			 var json=JSON.parse(data); //( data );			 	 
		  	var obj=json[0];
	 	   var list=new TableV3("table1");
		 
			list.bindData(json);
			
		});
			//mycallJava("submitx",$("#title").val(),$("#content").val(),dropIds);
		//}catch(e)
//		{
//			alert(e);
//		}
 
		//var orm=new atiOrmV4();
//		orm.obj=sql ;
//		//orm.metaParam="$utype=agent";
//		orm.notloginEventHandler=function(data)
//		{
//			  if(confirm("没有登录,请先登录。。"))
//				  {					
//					 window.location="../login/login.htm";
//					 return;
//				  }
//		}
//	orm.callbackFun=function(data)
//	{
//		
//			try{
//			  processJavaEx_V2q315(data);
//		   }catch(e)
//		   {
//			 
//				 
//				  showErr(e);
//				  return;
//		  
//		   }
//		   var json=str2json(data);
//		 
//		   var list=new TableV3("table1");
//		 
//			list.bindData(json);
//		   
//	};
//	orm.query();
		
	//	ini_mem_total();
	 today_add();
	
}

function calcCommission(money)
{
	//parseInt
	return ( money*0.08);
	
}